package com.cskaoyan.gateway.controller.user;

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.commons.tool.utils.CookieUtil;
import com.mall.user.ILoginServicesss;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import com.mall.user.dto.LoginResponse;
import com.mall.user.intercepter.TokenIntercepter;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import static com.mall.user.intercepter.TokenIntercepter.ACCESS_TOKEN;

@RestController
@RequestMapping("user")
public class UserLoginController {

    @Reference(timeout = 3000,retries = 0,check = false)
    ILoginServicesss iLoginService;


    @GetMapping("login")
    @Anoymous
    public ResponseData loginVerify(HttpServletRequest request){
        String token= CookieUtil.getCookieValue(request, ACCESS_TOKEN);
        if (token == null){
            return new ResponseUtil().setErrorMsg(SysRetCodeConstants.TOKEN_VALID_FAILED.getMessage());
        }
        LoginResponse loginResponse = iLoginService.login(token);
        return new ResponseUtil().setData(loginResponse);
    }

}
